package com.banana.manager.forest.service.impl.user;

import com.banana.manager.forest.dao.userandinfo.ILogDao;
import com.banana.manager.forest.entity.user.LogBean;
import com.banana.manager.forest.service.iuser.ILogService;
import com.banana.manager.forest.util.PageInfoSize;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.time.LocalDate;
@Service
@Transactional
public class LogServiceImpl implements ILogService {

    @Resource
    private ILogDao logDao;

    @Override
    public LogBean addNewLog(LogBean logBean) {
        logDao.insert(logBean);
        return logDao.selectById(logBean.getLogId());
    }

    @Override
    public PageInfo<LogBean> findAllByPage(Integer page, LocalDate start, LocalDate end) {
        QueryWrapper<LogBean> pageChange = new QueryWrapper<>();
        pageChange.ge("log_date",start);
        pageChange.le("log_date",end);
        PageHelper.startPage(page, PageInfoSize.pageSize);
        return PageInfo.of(logDao.selectList(pageChange));
    }
}
